/**
 * VYPe11 Project
 * VYPe11 language compiler.
 * Authors: Jozef Lang (xlangj01), 
 * 			Zoltan Zemko (xzemko01)
 * 2011
 */
package cz.vutbr.fit.VYPe.team18.VYPe11.codegeneration.MIPS32;

import java.util.*;

import cz.vutbr.fit.VYPe.team18.VYPe11.codegeneration.IVariableSet;

/**
 * Variable set implementation as a HashMap indexed by a variable name. 
 * It stores an address in DataStack for each variable.
 * Implementation is not thread-safe and should NOT be used in multi-threaded environment.
 */
public final class MIPS32VariableSet extends HashMap<String, Integer> implements IVariableSet {
	
	@Override
	public void addVariable(final String name, final Integer address) {
		if (super.containsKey(name)) {
			throw new UnsupportedOperationException("Variable already stored");
		}
		super.put(name, address);
	}

	@Override
	public int getVariable(final String name) {
		Integer address = super.get(name);
		if (address == null) {
			throw new IllegalArgumentException(String.format("Variable %s does not exists", name));
		}
		return address.intValue();
	}

	@Override
	public void removeVariable(final String name) {
		super.remove(name);
	}

}
